package com.newtouch.bxzs.business.train.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.business.train.model.bo.ExaminationPaperSetExaminationQuestionListBO;
import com.newtouch.bxzs.business.train.model.bo.ExaminationQuestionListBO;
import com.newtouch.bxzs.business.train.model.bo.QuestionBankSetExaminationQuestionListBO;
import com.newtouch.bxzs.common.base.model.ExaminationQuestion;

/**
 * 试题mapper
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021年2月5日</td>
 * <td>dongjinlin</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author dongjinlin
 * 
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface ExaminationQuestionMapper extends BaseMapper<ExaminationQuestion> {
	/**
	 * 题库设置试题查询列表
	 * 
	 * @param questionBankId
	 * @param startPage
	 * @param endPage
	 * @return
	 */
	IPage<QuestionBankSetExaminationQuestionListBO> getQuestionBankSetExaminationQuestionList(
			@Param("questionBankId") String questionBankId,@Param("page")Page<QuestionBankSetExaminationQuestionListBO> page);

	
	/**
	 * 题库设置试题查询列表总数
	 * 
	 * @param questionBankId
	 * @return
	 */
	@Select(" SELECT COUNT(1) FROM ASSISTANT_EXAMINATION_QUESTIONS eq INNER JOIN ASSISTANT_EXAMINATION_QUESTIONS_OPTION eqo ON eq.EXAMINATION_QUESTIONS_ID=eqo.EXAMINATION_QUESTIONS_ID"
			+ " WHERE eq.QUESTION_BANK_ID=#{questionBankId} OR eq.QUESTION_BANK_ID  IS NULL AND eq.IS_DELETE=0 and eqo.IS_DELETE=0 AND eqo.IS_CORRECT=1"
			+ " order by eq.CREATE_TIME desc")
	Integer getQuestionBankSetExaminationQuestionTotal(@Param("questionBankId") String examinquestionBankIdationId);
	
	

	

	/**
	 * 查询试卷设置试题列表
	 * @param startPage
	 * @param endPage
	 * @return
	 */
	@Select(" SELECT eq.EXAMINATION_QUESTIONS_ID,(SELECT epeqm.EXAMINATION_QUESTIONS_ID FROM ASSISTANT_EXAMINATION_PAPER_EXAMINATION_QUESTIONS_MAP epeqm WHERE EXAMINATION_PAPER_ID=#{examinationPaperId} and epeqm.EXAMINATION_QUESTIONS_ID=eq.EXAMINATION_QUESTIONS_ID ) as ifThisExaminationQuestion,"
			+" eq.EXAMINATION_QUESTIONS_TITLE,eq.IS_MULTIPLE_CHOICE,eq.CREATE_TIME,"
			+" (SELECT GROUP_CONCAT(eqop.EXAMINATION_QUESTIONS_OPTION_ID) FROM ASSISTANT_EXAMINATION_QUESTIONS_OPTION eqop"
			+" WHERE eqop.EXAMINATION_QUESTIONS_ID=eq.EXAMINATION_QUESTIONS_ID AND IS_CORRECT=1 AND eqop.IS_DELETE=0"
			+" GROUP BY eqop.EXAMINATION_QUESTIONS_ID) AS EXAMINATION_QUESTIONS_OPTION_ID,"
			+" (SELECT GROUP_CONCAT(eqop.EXAMINATION_QUESTIONS_OPTION) FROM ASSISTANT_EXAMINATION_QUESTIONS_OPTION eqop"
			+" WHERE eqop.EXAMINATION_QUESTIONS_ID=eq.EXAMINATION_QUESTIONS_ID AND IS_CORRECT=1 AND eqop.IS_DELETE=0"
			+" GROUP BY eqop.EXAMINATION_QUESTIONS_ID) AS EXAMINATION_QUESTIONS_OPTION"
			+" FROM ASSISTANT_EXAMINATION_QUESTIONS eq INNER JOIN ASSISTANT_EXAMINATION_QUESTIONS_OPTION eqo ON eq.EXAMINATION_QUESTIONS_ID=eqo.EXAMINATION_QUESTIONS_ID"
			+" WHERE  eq.IS_DELETE=0 and eqo.IS_DELETE=0 AND eqo.IS_CORRECT=1"
			+" GROUP BY eq.EXAMINATION_QUESTIONS_ID,eq.EXAMINATION_QUESTIONS_TITLE,IS_MULTIPLE_CHOICE,eq.CREATE_TIME"
			+" order by eq.CREATE_TIME desc")
	IPage<ExaminationPaperSetExaminationQuestionListBO> getExaminationPaperSetExaminationQuestionList(
			@Param("examinationPaperId") String examinationPaperId,@Param("page")Page<ExaminationPaperSetExaminationQuestionListBO> page);

	/**
	 * 查询试卷设置试题列表
	 * @return
	 */
	@Select(" SELECT COUNT(1) FROM ASSISTANT_EXAMINATION_QUESTIONS eq INNER JOIN ASSISTANT_EXAMINATION_QUESTIONS_OPTION eqo ON eq.EXAMINATION_QUESTIONS_ID=eqo.EXAMINATION_QUESTIONS_ID"
			+ " WHERE eq.IS_DELETE=0 and eqo.IS_DELETE=0 AND eqo.IS_CORRECT=1 order by eq.CREATE_TIME desc")
	Integer getExaminationPaperSetExaminationQuestionTotal(@Param("examinationPaperId") String examinationPaperId);
	
	/**
	 * 查询试题列表
	 * @param examinationQuestionsTitle
	 * @param isMultipleChoice
	 * @param startPage
	 * @param endPage
	 * @return
	 */
    IPage<ExaminationQuestionListBO> getExaminationQuestionList(
        @Param("examinationQuestionsTitle") String examinationQuestionTitle,
        @Param("isMultipleChoice") Integer isMultipleChoice, @Param("page")Page<ExaminationQuestionListBO> page);
	
	/**
	 * 查询试题列表总数
	 * @param examinationQuestionsTitle
	 * @param isMultipleChoice
	 * @return
	 */
	Integer getExaminationQuestionListTotal(@Param("examinationQuestionsTitle") String examinationQuestionsTitle,
			@Param("isMultipleChoice") Integer isMultipleChoice);
}
